import { formatFieldValue } from '@/views/project/utils/formatters.js';

export const projectGradingDescriptionFileds = (response) => {
  // 映射对象
  const autonomousTypeMap = {
    '1': '自主集成',
    '2': '自主研发',
    '3': '自主运维',
    '4': '自主交付',
    '5': '基础管理'
  };
  // const autonomousTypeMap = {
  //   '0': '非自主项目',
  //   '1': '自主项目管理',
  //   '2': '自主集成',
  //   '3': '自主开发',
  //   '4': '自主服务',
  //   '5': '自主应用'
  // };
  
  // 格式化函数
  const formatAutonomousType = (value) => {
    if (!value) return '';
    return value
      .split(',')
      .map(num => autonomousTypeMap[num] || '')
      .filter(text => text)
      .join(',');
  };

  const preProjectGradingInfoDesc = reactive([
    {
      label: '预定级等级',
      filed: 'pre_determined_level',
      content: response.pre_determined_level
    },
    {
      label: '客户重要程度',
      filed: 'pre_customer_importance',
      content: formatFieldValue('customer_importance', response.pre_customer_importance)
    },
    {
      label: '项目规模',
      filed: 'pre_project_scale',
      content: response.pre_project_scale,
    },
    {
      label: '项目交付复杂度',
      filed: 'pre_deliver_complex',
      content: response.pre_deliver_complex,
    },
    {
      label: '自有业务占比',
      type: 'input',
      filed: 'pre_owned_business',
      content: response.pre_owned_business,
    },
    {
      label: '项目收益',
      type: 'input',
      filed: 'pre_project_benefits',
      content: response.pre_project_benefits,
    },
    {
      label: '项目自主类型',
      filed: 'pre_autonomous_type',
      content: formatAutonomousType(response.pre_autonomous_type)
    },
    {
      label: '项目自主等级',
      type: 'readonlyInput',
      filed: 'pre_autonomous_type_level',
      content: response.pre_autonomous_type_level
    }
  ])

  // 项目定级信息动态数据
  const projectGradingInfoDesc = reactive([
    {
      label: '售前项目等级',
      type: 'select',
      options: [
        {
          value: 'Z-S',
          label: 'Z-S'
        },
        {
          value: 'Z-A',
          label: 'Z-A'
        },
        {
          value: 'Z-B',
          label: 'Z-B'
        },
        {
          value: 'Z-C',
          label: 'Z-C'
        },
        {
          value: 'Z-D',
          label: 'Z-D'
        }
      ],
      filed: 'project_level',
      content: response.project_level
    },
    {
      label: '客户重要程度',
      type: 'select',
      options: [
        {
          value: '3',
          label: '高'
        },
        {
          value: '2',
          label: '中'
        },
        {
          value: '1',
          label: '低'
        }
      ],
      filed: 'customer_importance',
      content: formatFieldValue('customer_importance', response.customer_importance)
    },
    {
      label: '项目规模',
      type: 'input',
      filed: 'project_scale',
      content: response.project_scale,
      validator: 'number'
    },
    {
      label: '项目交付复杂度',
      type: 'input',
      filed: 'project_complexity',
      content: response.project_complexity,
      validator: 'number'
    },
    {
      label: '自有业务占比',
      type: 'input',
      filed: 'self_business_proportion',
      content: response.self_business_proportion,
      validator: 'number'
    },
    {
      label: '项目收益',
      type: 'input',
      filed: 'project_income',
      content: response.project_income,
      validator: 'number'
    },
    // {
    //   label: '项目自主类型',
    //   type: 'multipleSelect',
    //   options: [
    //     {
    //       value: '0',
    //       label: '非自主项目'
    //     },
    //     {
    //       value: '1',
    //       label: '自主项目管理'
    //     },
    //     {
    //       value: '2',
    //       label: '自主集成'
    //     },
    //     {
    //       value: '3',
    //       label: '自主开发'
    //     },
    //     {
    //       value: '4',
    //       label: '自主服务'
    //     },
    //     {
    //       value: '5',
    //       label: '自主应用'
    //     }
    //   ],
    //   filed: 'autonomous_type',
    //   content: formatAutonomousType(response.autonomous_type)
    // },
    {
      label: '解决方案经理姓名',
      type: 'input',
      filed: 'solution_manager_name',
      content: response.solution_manager_name
    },
    {
      label: '解决方案经理电话',
      type: 'input',
      filed: 'solution_manager_phone',
      content: response.solution_manager_phone,
      validator: 'phone'
    },
    {
      label: '解决方案经理工号',
      type: 'input',
      filed: 'solution_manager_number',
      content: response.solution_manager_number
    }
  ])

  // 项目定级信息表单对象
  const projectGradingInfoForm = reactive({
    // predetermined_level: '',
    project_level: response.pre_determined_level || response.project_level,
    customer_importance: response.pre_customer_importance || response.customer_importance,
    project_scale: response.pre_project_scale || response.project_scale,
    project_complexity: response.pre_deliver_complex || response.project_complexity,
    self_business_proportion: response.pre_owned_business || response.self_business_proportion,
    project_income: response.pre_project_benefits || response.project_income,
    // autonomous_type: response.pre_autonomous_type?.split(',') ?? [],
    // autonomous_type_level: response.pre_autonomous_type_level,
    // autonomous_group: '',
    // autonomous_name: '',
    solution_manager_name: response.solution_manager_name || '',
    solution_manager_phone: response.solution_manager_phone || '',
    solution_manager_number: response.solution_manager_number || ''
  })

  const autonomousAbilityDesc= reactive({
    autonomous_type: formatAutonomousType(response.autonomous_type),
    autonomous_type_level: response.autonomous_type_level,
    autonomous_group: response.autonomous_group || '',
    autonomous_name: response.autonomous_name || '',
  })

  const projectGradingSecondInfoDesc = reactive([
    {
      label: '建设单位部门经理',
      type: 'input',
      filed: 'construction_department_manager',
      content: response.construction_department_manager
    }
  ])

  return {
    formatAutonomousType,
    // 项目定级信息
    preProjectGradingInfoDesc,
    projectGradingInfoDesc,
    projectGradingInfoForm,
    autonomousAbilityDesc,
    projectGradingSecondInfoDesc
  }
}